import rclpy
from rclpy.node import Node
from autopartol_interfaces.srv import SpeachText
import espeakng

class SpeakerNode(Node):
    def __init__(self,name):
        super().__init__(name)
        self.speach_service_=self.create_service(SpeachText,
                                "speach_text",self.speak_text_callback)
        self.speaker_=espeakng.Speaker()
        self.speaker_.voice='zh'

    def speak_text_callback(self,request,response):
        self.get_logger().info(f'正在准备朗读：{request.text}')
        self.speaker_.say(request.text)
        self.speaker_.wait()
        response.result=True
        return response
    

def main(args=None):
    rclpy.init(args=args)
    node=SpeakerNode("speaktext_node")
    rclpy.spin(node)
    node.destroy_node()
    rclpy.shutdown()